﻿

namespace LongRunningTask
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello, World!");
            LongRunningTask();

        }

        private static void LongRunningTask()
        {
            var t1 = new Task(TaskMethod, "long running", TaskCreationOptions.LongRunning);
            t1.Start();
            Console.ReadLine();
        }

        private static void TaskMethod(object o)
        {
            Log(o?.ToString());
        }

        private static object s_logLock = new object();
        private static void Log(string title)
        {
            lock (s_logLock)
            {
                Console.WriteLine(title);
                Console.WriteLine($"Task id:{Task.CurrentId?.ToString() ?? "no task"}," + $"thread:{Thread.CurrentThread.ManagedThreadId}");
            }
        }
    }
}
